﻿/*
 *  Copyright (C) 2010 by Benjamin Nolmans <benjamin.nolmans@gmail.com>
 *  and Barbara Post <postb99@gmail.com>
 *  Copyright (C) 2010 by Barbara Post postb99@gmail.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

using System.Collections.Generic;
using OsamesFrameworkCore.Logging;

namespace OsamesFrameworkCore.Xml.Types
{
    public class XmlDictionarySection
    {
        #region attributes

        private readonly Dictionary<string, string> _xmlTagDictionary = new Dictionary<string, string>();
        #endregion
        
        #region methods

        /// <summary>
        /// Safe add.
        /// </summary>
        /// <param name="strXmlNode_"></param>
        /// <param name="xmlNodeValue_"></param>
        internal void Add(string strXmlNode_, string xmlNodeValue_)
        {
            if (!_xmlTagDictionary.ContainsKey(strXmlNode_))
                _xmlTagDictionary.Add(strXmlNode_, xmlNodeValue_);
            else
                LoggerService.LogToOutput("Node ["+strXmlNode_+"] already exists in configuration");
        }

        /// <summary>
        /// Find value with exception on not found node in section.
        /// </summary>
        /// <param name="strXmlNode_"></param>
        /// <returns></returns>
        internal string FindValue(string strXmlNode_)
        {
            if (_xmlTagDictionary.ContainsKey(strXmlNode_))
                return _xmlTagDictionary[strXmlNode_];

            XmlDictionaryException err = new XmlDictionaryException(string.Format(XmlDictionaryException.CST_STR_ERROR_NODE_0_NOT_FOUND, strXmlNode_));
            //LoggerService.LogToOutput(err.Message);
            throw err;
        } 

        /// <summary>
        /// 
        /// </summary>
        /// <param name="strXmlNode_"></param>
        /// <param name="strValue_"></param>
        internal void SetValue (string strXmlNode_, string strValue_)
        {
            _xmlTagDictionary[strXmlNode_] = strValue_;
        }
        #endregion
    }
}
